package com.atguigui.leetcode1;

/**
 * 2331.计算布尔二叉树的值
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/2/6 9:00
 */
public class P2331EvaluateBooleanBinaryTree {

    public static void main(String[] args) {
        Solution solution = new P2331EvaluateBooleanBinaryTree().new Solution();
        // TO TEST
    }

    class Solution {
        public boolean evaluateTree(TreeNode root) {
            if (root.left == null) {
                return root.val == 1;
            }
            if (root.val == 2) {
                return evaluateTree(root.left) || evaluateTree(root.right);
            } else {
                return evaluateTree(root.left) && evaluateTree(root.right);
            }
        }
    }


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
